﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Text;
using NewThinkings.BusinessLayer.BusinessObject;

namespace Presentation.WebApp.Mods.Front
{
    public class CApplicationUI
    {
        #region Private member
        public CApplication Application;
        #endregion

        #region Public property

        #endregion

        #region Constructor
        public CApplicationUI(CApplication app)
        {
            Application = app;
        }
        public CApplicationUI() { }
        #endregion

        #region Dispose

        #endregion

        #region Infomation

        public static string GetApplicationImage()
        {
            System.Threading.Thread.Sleep(15);
            string[] css = { "ss_rosette", "ss_shield", "ss_page_white_office", "ss_package", "ss_chart_bar", "ss_chart_line", "ss_coins", "ss_eye", "ss_group" };
            string sprite = string.Format("<span class='ss_sprite {0}'> &nbsp;</span>",
                css[new Random().Next(css.Length)]);
            return sprite;
        }
       
        public string GetHtmlWithModule()
        {
            //<li>
            //    <a href="#">Weblog Tools</a>
            //    <ul>
            //        <li><a href="http://www.pivotx.net/">PivotX</a></li>
            //        <li><a href="http://www.wordpress.org/">WordPress</a></li>
            //        <li><a href="http://www.textpattern.com/">Textpattern</a></li>
            //        <li><a href="http://typosphere.org/">Typo</a></li>
            //    </ul>
            //</li>

            StringBuilder ret = new StringBuilder();
            ret.Append("<li>");
            //ret.Append("<img src='../../Images/Nav/Home.png' class='iconAccordion' />");
            //ret.Append(GetApplicationImage());
            ret.Append(string.Format("<a href='javascript:void(0);' link='{0}' id='App_{1}' tabid='a{1}' isLoad='0' RetainPage='{2}'>{3} {4}</a>",
                            Application.LinkURL,
                            Application.ID,
                            Application.RetainPage,
                            GetApplicationImage(),
                            Application.Name));

            //Get Interface Function Group of Application ----------------------------------------
            //CSession session = new CSession();
            //IList<CModule> listModule = new CCoreFacade().GetModuleByApplicationID(
            //            session.User.ID,
            //            session.SessionID.ToString(),  
            //            Application.ID, 
            //            session.LanguageID);
            //ret.Append(CModuleUI.GetHtml(listModule));
            //------------------------------------------------------------------------------
            ret.Append("</li>");
            return ret.ToString();
        }
       
        #endregion

        #region Infomation - Static
        public static string GetHtml(IList<CApplication> listApp)
        {
            StringBuilder ret = new StringBuilder();

            foreach (CApplication app in listApp)
            {
                CApplicationUI appUI = new CApplicationUI(app);
                ret.Append(appUI.GetHtmlWithModule());
            }

            return ret.ToString();
        }
        #endregion
    }
}